<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<div id="app">
    <ipt-com v-model:msg="msg" v-model:msg2="msg2"></ipt-com>
    <h1>msg:{{msg}}</h1>
    <h1>msg2:{{msg2}}</h1>
</div>
</body>

</html>
<!-- 组件结构 -->
<template id="ipt">
    <fieldset>
        <legend>v3的组件使用v-model</legend>
        <input type="text" :value="msg" @input="handleInput">
        <br>
        <input type="text" :value="msg2" @input="handleInput2">
    </fieldset>
</template>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
    let app = Vue.createApp({
        data() {
            return {
                msg: 'v3',
                msg2: 'vv3'
            }
        }
    })

    //创建组件

    //组件使用v-model的流程基础语法:
    //1.props默认接受的是modelValue

    //2.默认触发的事件 update:modelValue

    //绑定多个v-model的时候

    //流程:

    //1.props默认接受的值就是定义的指令参数名

    //2.触发事件的时候应该是update:指令参数名

    app.component('ipt-com', {
        template: "#ipt",
        props: ['msg', 'msg2'],
        methods: {
            handleInput(e) {
                this.$emit('update:msg', e.target.value)
            },
            handleInput2(e) {
                this.$emit('update:msg2', e.target.value)
            }
        }
    })


    app.mount('#app')

</script>